<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>修改密码</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/${BasePath}/static/layui/css/layui.css" media="all" type="text/css">
    <link rel="stylesheet" href="/${BasePath}/static/css/public.css" media="all" type="text/css">
</head>
<body class="childrenBody">
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
	  <legend>忘记密码</legend>
	</fieldset>
	<form class="layui-form layui-row changePwd" id="changePwd">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<div class="layui-input-block layui-red pwdTips">如忘记账户邮箱，请联系管理员 TEL:17605814756</div>
			<div class="layui-form-item">
				<label class="layui-form-label">邮箱</label>
				<div class="layui-input-block">
					<input type="text" value="" id="userName" name="username" placeholder="请输入注册邮箱" lay-verify="required" class="layui-input pwd">
				</div>
			</div>		
			<div class="layui-row">
			    <div class="layui-col-xs6">
			      <div class="grid-demo grid-demo-bg1">
					<div class="layui-form-item">
						<label class="layui-form-label">验证码</label>
						<div class="layui-input-block">
							<input type="text" name="code" value="" lay-verify="required"  class="layui-input" placeholder="请输入验证码" >
						</div>
					</div>		      
			      </div>
			    </div>
			    <div class="layui-col-xs6">
			      <div class="grid-demo">
					<div class="layui-form-item">
						<div class="layui-input-block">
							<input type="button" id="btn"  class="layui-btn layui-btn-warm" value="免费获取验证码" lay-verify="required" onclick="sendCode(this)" />
						</div>
					</div>		      
			      </div>
			    </div>
	        </div>
			<div class="layui-form-item">
				<label class="layui-form-label">新密码</label>
				<div class="layui-input-block">
					<input type="password" value="" id="passwordNew" name="password" placeholder="请输入新密码" lay-verify="required" class="layui-input pwd">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">确认密码</label>
				<div class="layui-input-block">
					<input type="password" value="" id="passwordNewT"  placeholder="请确认密码" lay-verify="required" class="layui-input pwd">
				</div>
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" type="button" lay-submit lay-filter="form">立即修改</button>
			</div>
		</div>
	</form>


<script src="/${BasePath}/static/layui/layui.js" charset="utf-8" type="text/javascript"></script>
<script type="text/javascript" src="/${BasePath}/static/js/common/jquery-2.1.0.min.js"></script>
    <script type="text/javascript">
    layui.use(['form'], function() {
        var form = layui.form,
            layer = layui.layer

            form.on('submit(form)', function() {
            	 if($("#passwordNew").val()!=$("#passwordNewT").val()){
                 	layer.msg('两次密码不一致！');
                 	return
                 }
                     $.ajax({
                         cache: true,
                         type: "POST",
                         url: "/${BasePath}/user/savePwd",
                         data: $('#changePwd').serialize(),
                         async: false,
                         error: function(request) {
                             layer.msg('系统错误！');
                         },
                         success: function(data) {
                             if(data.code == "1") { 
                            	 layer.alert(data.msg, function(){ 
                            		 window.location.href="/${BasePath}/user/login"; 
                       		     }); 
                             } else {
                                 layer.msg(data.msg);
                             }
                         }
                     });
            })     

    });
    
    var countdown = 60;
    
    function sendCode(obj){
        $.ajax({
            cache: true,
            type: "POST",
            url: "/${BasePath}/user/sendMailCode",
            data: {"userName":$("#userName").val()},
            async: false,
            error: function(request) {
                layer.msg('系统错误！');
            },
            success: function(data) {
            	if(data.code == "1"){
            		settime(obj)
            	}
            	layer.msg(data.msg);
            }
        });
        
    }
    
    function settime(obj) {
        if (countdown == 0) {
            obj.removeAttribute("disabled");
            obj.value="免费获取验证码";
            countdown = 60;
            return;
        } else {
            obj.setAttribute("disabled", true);
            obj.value="重新发送(" + countdown + ")";
            countdown--;
        }
    setTimeout(function() {
        settime(obj) }
        ,1000)
    }

    </script>
</body>
</html>